//
//  AddressList.m
//  111
//
//  Created by WuXushun on 16/2/22.
//  Copyright © 2016年 wuxushun. All rights reserved.
//

#import "AddressList.h"

@interface AddressList ()

@property (nonatomic, strong) NSDictionary *sourceDic;

@end
@implementation AddressList

- (instancetype)init
{
    self = [super init];
    if (self) {
        
        [self loadPlist];
        
    }
    return self;
}

-(void)loadPlist{

    self.sourceDic = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Address" ofType:@"plist"]];

    
}

-(NSArray *)handlePlist{

    NSMutableArray *temp = [NSMutableArray new];
    
    for (NSString *key in self.sourceDic) {
        
        NSMutableArray *tempCity = [NSMutableArray new];
        
        for (NSString *key2 in [[self.sourceDic objectForKey:key] objectAtIndex:0]) {
            
             NSDictionary *dic = [[NSDictionary alloc]initWithObjectsAndKeys:[[[self.sourceDic objectForKey:key] objectAtIndex:0] objectForKey:key2],@"AreaList",key2,@"cityName", nil];
            
            [tempCity addObject:dic];
            
        }
        
        NSDictionary *dic = [[NSDictionary alloc]initWithObjectsAndKeys:key,@"provinceName",tempCity,@"cityList", nil];
        
        [temp addObject:dic];
        
        
    }
    
    return temp;

}

-(NSArray *)dataFilterWithArray:(NSArray *)sourceData{

    NSMutableArray *temp = [NSMutableArray new];
    NSMutableArray *returnData = [NSMutableArray new];
    
    for (NSString *str in sourceData) {
        
        NSPredicate *preicate = [NSPredicate predicateWithFormat:@"provinceName CONTAINS[c] %@", str];
        
        NSArray *arr = [NSArray arrayWithArray:[[self handlePlist] filteredArrayUsingPredicate:preicate]];
        
        [temp addObject:arr];
        
    }
    
    for (id obj in temp) {
        
        for (id next in obj) {
            
            [returnData addObject:next];
            
        }
        
    }
    
    return returnData;
    
}

@end
